#!/bin/bash
###SHELLPACK preamble mlc-bench 3.4
MAX_THREADS=$NUMCPUS

###SHELLPACK parseargBegin
###SHELLPACK parseargInstall
###SHELLPACK parseargParam   --type		MLC_TYPE
###SHELLPACK parseargParam   --iterations	MLC_ITERATIONS
###SHELLPACK parseargEnd
###SHELLPACK monitor_hooks

###SHELLPACK check_install_required mlc-${VERSION}
###SHELLPACK init_complete

echo Disabling transparent hugepages as recommended by benchmark
echo never > /sys/kernel/mm/transparent_hugepage/enabled

echo Disabling automatic NUMA balancing
echo 0 > /proc/sys/kernel/numa_balancing

if [ "$MLC_TYPE" = "" ]; then
	die mlc benchmark is not specified
fi

ONE_HT_SWITCH=
if [ "$MLC_ONE_PER_HT" = "yes" ]; then
	ONE_HT_SWITCH=-X
fi

mmtests_activity $MLC_TYPE
monitor_pre_hook $LOGDIR_RESULTS $MLC_TYPE
###SHELLPACK iteration_begin $MLC_ITERATIONS
	echo Running iteration $ITERATION/$MLC_ITERATIONS
	$TIME_CMD -o $LOGDIR_RESULTS/$MLC_TYPE-$ITERATION.time \
		./Linux/mlc_avx512 --$MLC_TYPE $ONE_HT_SWITCH | tee $LOGDIR_RESULTS/$MLC_TYPE-$ITERATION.log
###SHELLPACK iteration_end
monitor_post_hook $LOGDIR_RESULTS $MLC_TYPE

if [ $? -ne 0 ]; then
	exit $SHELLPACK_ERROR
fi
exit $SHELLPACK_SUCCESS
